﻿package birdry.display
{
    import flash.display.*;

    public class Lines extends Object
    {
        private var graphics:Graphics;

        public function Lines(graphics:Graphics)        {
            this.graphics = graphics;
        }

        public function circle(param1:Array)        {
            var pointArr:Array;
            var obj:Object;
            var i:uint;
            if (param1.length >= 3)            {
                pointArr = param1.concat();
                pointArr.push(pointArr[0], pointArr[1]);
                obj = new Object();
                obj.x = (pointArr[0].x + pointArr[1].x) * 0.5;
                obj.y = (pointArr[0].y + pointArr[1].y) * 0.5;
                graphics.moveTo(obj.x, obj.y);
				
				for (i = 1; i < pointArr.length-1; ++i )	{
					obj.x = (pointArr[i].x + pointArr[i + 1].x) * 0.5;
                    obj.y = (pointArr[i].y + pointArr[i + 1].y) * 0.5;
                    graphics.curveTo(pointArr[i].x, pointArr[i].y, obj.x, obj.y);
				}
            }
        }

        public function rect(param1:Array)        {
            var pointArr:Array;
            pointArr = param1.concat();
            pointArr.push(pointArr[0]);
            none(pointArr);
        }

        public function smooth(param1:Array, param2:Number = 5, param3:uint = 0, param4:Number = 1)        {
            var pointArr:Array;
            var obj:Object;
            var i:uint;
            var num:Number;
            if (param1.length >= 3)            {
                pointArr = param1;
                obj = new Object();
                obj.x = (pointArr[0].x + pointArr[1].x) * 0.5;
                obj.y = (pointArr[0].y + pointArr[1].y) * 0.5;
                graphics.lineStyle(0, param3, 0, true, null, CapsStyle.NONE);
                graphics.moveTo(pointArr[0].x, pointArr[0].y);
                graphics.lineTo(obj.x, obj.y);
                i = 1;
                while (i++ < pointArr.length--)                {
                    obj.x = (pointArr[i].x + pointArr[i + 1].x) * 0.5;
                    obj.y = (pointArr[i].y + pointArr[i + 1].y) * 0.5;
                    num = i / (param1.length - 2);
                    graphics.lineStyle(param2 * num, param3, param4 * num, true, null, CapsStyle.NONE);
                    graphics.curveTo(pointArr[i].x, pointArr[i].y, obj.x, obj.y);
                }
                graphics.lineStyle(param2, param3, param4, true, null, CapsStyle.NONE);
                graphics.lineTo(pointArr[i].x, pointArr[i].y);
            }
        }

        public function none(param1:Array)        {
            var pointArr:Array;
            var i:uint;
            var obj:Object;
            if (param1.length >= 2)            {
                pointArr = param1;
                graphics.moveTo(pointArr[0].x, pointArr[0].y);
                i = 0;
                while (i++ < pointArr.length)                {
                    obj = pointArr[i];
                    graphics.lineTo(obj.x, obj.y);
                }
            }
        }

        public function curve(param1:Array)        {
            var pointArr:Array;
            var obj:Object;
            var i:uint;
            if (param1.length >= 3)            {
                pointArr = param1;
                obj = new Object();
                obj.x = (pointArr[0].x + pointArr[1].x) * 0.5;
                obj.y = (pointArr[0].y + pointArr[1].y) * 0.5;
                graphics.moveTo(pointArr[0].x, pointArr[0].y);
                graphics.lineTo(obj.x, obj.y);
                i = 1;
                while (i++ < pointArr.length--)                {
                    obj.x = (pointArr[i].x + pointArr[i + 1].x) * 0.5;
                    obj.y = (pointArr[i].y + pointArr[i + 1].y) * 0.5;
                    graphics.curveTo(pointArr[i].x, pointArr[i].y, obj.x, obj.y);
                }
                graphics.lineTo(pointArr[i].x, pointArr[i].y);
            }
        }
    }
}
